package smartvillage.mapper;

import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import smartvillage.dto.CommodityDTO;
import smartvillage.pojo.Commodity;
import smartvillage.vo.CommodityVO;

import java.util.List;

@Mapper
public interface CommodityMapper {
    //根据id查询商品信息
    @Select("select * from smartvillage.commodity_tb where id = #{id}")
    Commodity getCommodityById(Integer id);

    //查询所有未被购买的商品
    @Select("SELECT c.* " +
            "FROM smartvillage.commodity_tb c " +
            "LEFT JOIN smartvillage.order_tb o ON c.id = o.commodity " +
            "WHERE o.commodity IS NULL;")
    List<Commodity> getAllCommodity();

    //根据id删除商品
    @Delete("delete from smartvillage.commodity_tb where id = #{id}")
    void deleteCommodityById(Integer id);

    //新增商品
    @Insert("insert into smartvillage.commodity_tb values" +
            "(null, #{household}, #{name}, #{describe}, #{parameter}, #{img1}, #{img2}, #{price})")
    void insertCommodity(Commodity commodity);
}
